﻿using CPPEI.Coolzon.Event.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;

namespace CPPEI.Coolzon.Theme.Fashion.MainViewControl
{
    public partial class Header
    {
        /// <summary>
        /// 检测网络连接状态
        /// </summary>
        /// <param name="event"></param>
        [Common.Subscribe]
        public void OnReceiveNetStateFeedbackEvent(UINetConnectionStateFeedbackEvent @event)
        {
            this.Dispatcher.Invoke(() =>
            {
                if (@event.IsConnected())
                {
                    imgPilotLight.Source = new BitmapImage(new Uri("/WEITSM.Theme.Default;component/Images/bglv.png", UriKind.Relative));
                }
                else
                {
                    imgPilotLight.Source = new BitmapImage(new Uri("/WEITSM.Theme.Default;component/Images/bgh.png", UriKind.Relative));
                }

            });
        }

        /// <summary>
        /// 接收到性能监控报告事件
        /// </summary>
        /// <param name="event"></param>
        [Common.Subscribe]
        public void OnReceiveUIPerformanceMonitorReportEvent(Event.UI.UIPerformanceMonitorReportEvent @event)
        {
            this.Dispatcher.BeginInvoke(new Action<Event.UI.UIPerformanceMonitorReportEvent>(OnInvokeReceiveUIPerformanceMonitorReportEvent), @event);
        }

        private void OnInvokeReceiveUIPerformanceMonitorReportEvent(Event.UI.UIPerformanceMonitorReportEvent @event)
        {
            this._ctlTextCPU.Text = string.Format("{0:N0}%", @event.CurrentCPU);
            this._ctlTextMemory.Text = string.Format("{0:N0}", @event.CurrentPrivateWorkingSet);
        }

        public void OnReceiveUIGCCollectEvent(Event.UI.UIGCCollectEvent @event)
        {
            this.Dispatcher.BeginInvoke(new Action<Event.UI.UIGCCollectEvent>(OnInvokeReceiveUIGCCollectEvent), @event);
        
        }
        private void OnInvokeReceiveUIGCCollectEvent(Event.UI.UIGCCollectEvent @event)
        {
            if (@event.IsRunning)
            {
                _ctlTextGCRuning.Visibility = System.Windows.Visibility.Visible;
            }
            else
            {
                _ctlTextGCRuning.Visibility = System.Windows.Visibility.Hidden;
            }
        }
    }
}
